#ifndef __VESC_H__
#define __VESC_H__

#include "main.h"
#include "userCan.h"
#include "wxyLib.h"
#include <stdbool.h>

typedef struct VESC_Handle VESC_HandleTypeDef;

struct VESC_pf
{
	void (*currentMode)(VESC_HandleTypeDef* hvesc, float Current);
	void (*speedMode)(VESC_HandleTypeDef* hvesc, float Speed);
	void (*dutyMode)(VESC_HandleTypeDef* hvesc, float Duty);
	void (*staticBreakMode)(VESC_HandleTypeDef* hvesc, float BreakCurrent);
	void (*dynamicBreakMode)(VESC_HandleTypeDef* hvesc, float BreakCurrent);
	void (*posMode)(VESC_HandleTypeDef* hvesc, float Pos); 
	uint8_t (*getPos)(VESC_HandleTypeDef* hvesc, float *pos);
	uint8_t (*getCurrent)(VESC_HandleTypeDef* hvesc, float *current);
	uint8_t (*getSpeed)(VESC_HandleTypeDef* hvesc, float *speed);
};

typedef struct VESC_Status
{
	UserCAN_HandleTypeDef *hcan;
    uint8_t ID;
	uint8_t Poles;
	uint8_t gear_ratio;
    float speed;
    float posation;
	bool posRxFlag;
//    float torget;
	float current;
}VESC_Status;

struct VESC_Handle
{
	VESC_Status status;
	struct VESC_pf *pf;
	//gear_ratio should be equal to "VESC -> PID Controllers -> Position Angle Devision"
	//减速比应该等于 "VESC -> PID Controllers -> Position Angle Devision"
};




void VESC_Init(VESC_HandleTypeDef *hvesc, UserCAN_HandleTypeDef *hcan, uint8_t ID, uint8_t Poles, uint8_t gear_ratio);
void VESC_RxInit(uint8_t VESCNum, VESC_HandleTypeDef **VESCArray);
uint8_t VESC_Analysis(user_FDCAN_Rx_Struct *FDCAN_Rx_struct);


#endif 

/* Ê¾Àý³ÌÐò 

VESC_Init(&hcan1);

void main()
{
	while (1)
  	{
		VESC.pfSpeedLoopMode(1,60,VESC.enMAD_M6C18);
		HAL_Delay(100);
  	}
}

*/




